package CollectionDemo;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class IteratorTest {
    public static void main(String[] args) {
        Collection books = new HashSet();
        books.add("十七");
        books.add("你好");
        books.add("吵架");
        Iterator iterator = books.iterator();
        while (iterator.hasNext()) { //单纯判断cursor指针不等于size
            String book = (String)iterator.next();
            System.out.println(book);
            if (book.equals("吵架")) {
                //删除上次next返回的元素
                iterator.remove();
                //我估计这个会出错,因为每删除一次，lastRet会置为-1，除非你再进行一次next使得lastRet变为上一次next的元素位置
                //iterator.remove();
            }
            book = "ace";

        }
        System.out.println(books);
    }
}
